<?php

	namespace app\common\middleware;

	use think\facade\Log;

    /**
	 * 访问环境检查，是否是微信或支付宝等
	 */
	class InApp
	{
		public function handle($request, \Closure $next)
		{
//            Log::write( $request->header());
            if ($request->header('user-agent'))
            {
                if (preg_match('~micromessenger~i', $request->header('user-agent'))) {
                    $request->client = 'WeChat';
                } else if (preg_match('~alipay~i', $request->header('user-agent'))) {
                    $request->client = 'Alipay';
                } else if (preg_match('~alipay~i', $request->header('user-agent'))) {
                    $request->client = 'Alipay';
                }else if (preg_match('~phpUnit~', $request->header('user-agent'))) {
                    $request->client = 'test';
                } else {
                    $request->client = 'Pc';
                }
            }else{
                $request->client = 'Cmd';
            }

			return $next($request);
		}
	}